fix: Fix bug with structurally equal correlated subqueries#22313
Open
neilconway wants to merge 2 commits into
Open
fix: Fix bug with structurally equal correlated subqueries#22313neilconway wants to merge 2 commits into
neilconway wants to merge 2 commits into
Conversation
kosiew
approved these changes
May 19, 2026
Contributor
There was a problem hiding this comment.
@neilconway
Thanks for the fix here. I walked through the rewrite flow and the approach makes sense overall. I just had one small suggestion that could make the bookkeeping a bit more explicit and easier to reason about in the future.
Contributor
Author
|
@kosiew Thanks for the review! Let me know if you have any additional feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
If a query contained two or more structurally equal correlated subqueries, we previously would produce incorrect query results. This was caused by using
Subqueryas a hashmap key; if we use the subquery alias instead, we can avoid the unintended key collision. Using the alias (a string) as the hashmap key is also safer and more efficient than hashing on a complex type likeSubquery.What changes are included in this PR?
ScalarSubqueryToJoinrewrite passAre these changes tested?
Yes, with new test added.
Are there any user-facing changes?
No, aside from fixing the previously incorrect query results.